// <link rel="stylesheet" href="./css/goods_common.css">
// <link rel="stylesheet" href="./css/goods_custom.css">
// <link rel="stylesheet" href="./css/goods.css">
// <link rel="stylesheet" href="./css/goods_theme.css">
// <link rel="stylesheet" href="./css/goods_mars.css">
// <link rel="stylesheet" href="./css/goods_sku.css">

import './goods_common.css'
import './goods_custom.css'
import './goods.css'
import './goods_theme.css'
import './goods_mars.css'
import './goods_sku.css'
import './goods_sku_transition.css'

import Vue from 'vue'
import url from 'js/api.js'
import axios from 'axios'
import mixin from 'js/mixin.js'
import qs from 'qs'
import Swipe from 'components/Swipe.vue'

let { id } = qs.parse(location.search.substr(1));
let tabArray = ['商品详情', '本店成交'];
console.log(id)
new Vue({
  el: '#app',
  data: {
    details: null,
    tabArray,
    tabIndex: 0,
    bannerArray: [],
    skuShow: false,
    // 店铺 1  购物车 2 购买 3
    skuType: 0,
    skuNum: 1,
    isAddCart: false,
    showAddMessage: false

  },
  components: {
    Swipe
  },
  created(){
    console.log('created....')
    this.getDetails();
  },
  watch: {
    skuShow(val, oldVal){
        document.body.style.overflow = val ? 'hidden' : 'auto';
        document.body.style.height = val ? '100%' : 'auto';
        document.documentElement.style.overflow  = val ? 'hidden' : 'auto';
      document.documentElement.style.height  = val ? '100%' : 'auto';
    }
  },
  methods: {
    getDetails() {
      console.log(url.details)
      axios.get(url.details, {
        params:{ id }
      }).then(res=>{
        this.details = res.data.data;
        this.bannerArray = res.data.data.imgs.map((item, index)=>{
          return {
            id: index,
            img: item
          }
        })
      })
    },
    tabChange(index){
      this.tabIndex = index;
    },
    showSku(index){
      this.skuType = index;
      this.skuShow = true;
    },
    changeSkuNum(num){
      if(num < 0 && this.skuNum === 1){
        return
      }
      this.skuNum += num;
    },
    addCart(){
      axios.post(url.cartAdd, {
          id,
          num: this.skuNum
      }).then(res=>{
        console.log(res)
        if(res.data.status === 200){
          this.isAddCart = true;
          this.skuShow = false;
          this.showAddMessage = true;
          setTimeout(()=>{
            this.showAddMessage = false;
          }, 2000)
        }else {
          console.log('没有')
        }
        }
      )
    }
  },
  mixins: [mixin]
});
